import { Injectable } from '@angular/core';
import {RequestUtil} from "../../../util/request-util";
import {API} from "../../../constants/constants";
import {Observable} from "rxjs";
import {MsgResult} from "../../../models/msg-result";

@Injectable()
export class PortalsService {

  constructor(
    private requestUtil : RequestUtil
  ) { }

  //无参初始化数据
  getPortals():Observable<MsgResult>{
    return this.requestUtil.get(API.getPortals);
  }

  //添加门户信息
  insertPortal(portal):Observable<MsgResult>{
    let params="name="+portal.name+"&code="+portal.code+"&isDefault="+portal.isDefault+"&isEnable="+portal.isEnable;
    return this.requestUtil.post(API.insertPortal,params);
}

  //删除门户信息
  deletePortal(id):Observable<MsgResult>{
    let params= "id="+id;
    return this.requestUtil.get(API.deletePortal,params);
  }

  //根据id查询
  getPortalById(id):Observable<MsgResult>{
    let params= "id="+id;
    return this.requestUtil.get(API.getPortalById,params);
  }

  //分页查询
  getPortalByFuzzy(searchValue):Observable<MsgResult>{
    let params= "searchValue="+searchValue;
    // return this.requestUtil.get(API,params);
    return null;
  }

  //修改门户
  updatePortal(portal):Observable<MsgResult>{
    let params="id="+portal.id+"&name="+portal.name+"&code="+portal.code+"&isDefault="+portal.isDefault+"&isEnable="+portal.isEnable;
    return this.requestUtil.post(API.updatePortal,params);
  }


}
